package hai.com.android_test.utils;

import android.content.Context;

import com.lidroid.xutils.DbUtils;

import okhttp3.OkHttpClient;

/**
 * Created by 黄海 on 11/27/2016.
 */

public final class Helper {
    public static DbUtils dbUtils;

    private Helper() {
    }

    public static void init(Context context) {
        dbUtils = DbUtils.create(context);
        dbUtils.configAllowTransaction(true);
        dbUtils.configDebug(true);
    }

    private static OkHttpClient okHttpClient;

    public static void initHttpClient(OkHttpClient client) {
        if (okHttpClient == null) {
            synchronized (OkHttpUtils.class) {
                if (okHttpClient == null) {
                    okHttpClient = client;
                }
            }
        }
    }

    public static OkHttpClient getOkHttpClient() {
        if (okHttpClient == null)
            throw new NullPointerException("okHttpClient is null,please call initClient first");
        return okHttpClient;
    }
}
